package info.akabana.yui.examples.mobile.helloworld.helper
{
	import info.akabana.yui.examples.mobile.helloworld.view.HelloWorldFaultView;
	import info.akabana.yui.examples.mobile.helloworld.view.HelloWorldLoginView;
	import info.akabana.yui.examples.mobile.helloworld.view.HelloWorldResultView;
	import info.akabana.yui.examples.mobile.helloworld.vm.UserViewModel;

	import org.seasar.akabana.yui.framework.ns.viewpart;

	import spark.components.Button;
	import spark.components.TextInput;
	import spark.components.ViewNavigator;
	import spark.transitions.SlideViewTransition;
	import spark.transitions.ZoomViewTransition;

	use namespace viewpart;

	public class HelloWorldLoginHelper
	{
		viewpart var txtinptUserId:TextInput;
		viewpart var txtinptPassword:TextInput;
		viewpart var btnLogin:Button;
		viewpart var navigator:ViewNavigator;

		public function changeEnabledSendButton():void {
			btnLogin.enabled =
				txtinptUserId.text.length >= 1 &&
				txtinptPassword.text.length >= 1;
		}

		public function moveToResult():void {

			if (isLogin()) {

				var vm:UserViewModel = new UserViewModel();
				vm.userId = txtinptUserId.text;
				vm.password = txtinptPassword.text;

				navigator.pushView(HelloWorldResultView, vm);
			} else {
				var v:ZoomViewTransition = new ZoomViewTransition();
				navigator.pushView(HelloWorldFaultView, null, null, v);
			}
		}

		private function isLogin():Boolean {
			return txtinptUserId.text == "yfs" && txtinptPassword.text == "mx";
		}
	}
}